package cn.edu.zafu.bigdata.lmr;

import java.util.Random;
import java.util.Scanner;

public class GuessNumberGame {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();

        // 设置最大猜测次数
        int maxTries = 10;
        // 生成1到100之间的随机数
        int secretNumber = random.nextInt(100) + 1;
        int guess = 0;
        int tries = 0;

        System.out.println("猜数字游戏开始! 我已经想好了一个1到100之间的数字。");
        System.out.println("你有" + maxTries + "次机会猜中它。");

        while (tries < maxTries) {
            System.out.print("请输入你的猜测：");
            guess = scanner.nextInt();
            tries++;

            if (guess == secretNumber) {
                System.out.println("恭喜你！你在第" + tries + "次猜中了数字。");
                break;
            } else if (guess < secretNumber) {
                System.out.println("太小了！");
            } else if (guess > secretNumber) {
                System.out.println("太大了！");
            }

            System.out.println("你还有" + (maxTries - tries) + "次机会。");
        }

        if (guess != secretNumber) {
            System.out.println("很遗憾，你的猜测次数用完了。我想的数字是：" + secretNumber);
        }

        scanner.close();
    }
}